package spring.angularjs.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import spring.angularjs.domain.History;
import spring.angularjs.domain.json.HistoryTemp;
import spring.angularjs.services.Services;

@Controller
@RequestMapping(value = "/history")
public class HistoryController {

	@Autowired
	private Services services;

	@RequestMapping(value = "/start")
	public String goHistory() {
		return "detail/history";
	}

	@RequestMapping(value = "/getlist", method = RequestMethod.GET)
	@ResponseBody
	public List<HistoryTemp> getListHistory() {
		List<History> histories = services.histories();
		List<HistoryTemp> historyTemp = new ArrayList<HistoryTemp>();
		for (int i = 0; i < histories.size(); i++) {
			History history = histories.get(i);
			HistoryTemp hisTemp = new HistoryTemp(history.getId(), history
					.getUserinfo().getLoginId(), history.getStart(),
					history.getEnd());
			historyTemp.add(hisTemp);
		}
		return historyTemp;
	}
}
